(function ($) {
	var sourceData;
	var perInfo,pageType,perid
	var domArr = [{'domId':'NurLevel','tip':'请选择层级','type':'list','key':'NurLevel'},
			{'domId':'LevelDate','tip':'请选择晋升日期','type':'date','key':'LevelDate'},
			{'domId':'LevelFactor','tip':'请输入系数','type':'input','key':'LevelFactor'},
			{'domId':'LevelRemark','tip':'','type':'input','key':'LevelRemark'}]
	var unUploadFiles=[] //未上传的图片
	$.init();
	$.plusReady(function() {
		baseSetup();
	})
	if (!mui.os.plus) {
		baseSetup()
	}
	//NurLevel|19||5^LevelDate|2022-08-01^LevelFactor|5^LevelRemark|备注^RowID|1395^LevelPerDR|1
	function submitNewData(){
		blurAllInput()
		var parr = ''
		for (var i = 0; i < domArr.length; i++) {
			var oneDom = domArr[i]
			var dom = $('#'+oneDom['domId'])[0]
			var domValue = dom.getAttribute('data-id')
			domValue = (domValue == undefined?"":domValue)
			if (oneDom['type'] == 'input') {
				domValue = dom.value
			}else if (oneDom['type'] != 'list') {
				domValue = dom.innerText
			}
			if (domValue == '' && oneDom['tip']!= '') {
				mui.toast(oneDom['tip'])
				return
			}
			parr += oneDom['key']+'|'+domValue+'^'
		}
		if (sourceData) {
			parr += 'RowID|'+sourceData['levelRowID']+'^'
		}else{
			parr += 'RowID|^'
		}
		parr += 'LevelPerDR|'+perid
		var status = this.getAttribute('data-id');
		//console.log(parr+" "+status)
		var pdict = {'parr':parr,'type':status}
		var paramDict = {'method':'web.INMPersonComm:SaveLevel','params':JSON.stringify(pdict),'type':'Method'}
		$.DHCWebService(paramDict, function(result) {
			//console.log(JSON.stringify(result))
			var msgcode =result['msgcode']
			if (msgcode == '-1') {
				mui.toast(result['msg'])
				return 
			}
			plus.webview.getWebviewById('../WKPlatformPages/apply/applyList.html').evalJS('detailChanged()')
			mui.back()
		}, function(errorStr) {
			mui.toast(errorStr)
		});
	}
	
	function getTransDetail(){
		var pdict = {'id':sourceData['levelRowID']};
		//console.log(id + ' ' + method)
		var paramDict = {'method':'web.INMPersonComm:GetLevelItem','params':JSON.stringify(pdict),'type':'RecMethod'}
		$.DHCWebService(paramDict, function(result) {
			//console.log(JSON.stringify(result))
			var dataDict = result.data
			updateUI(dataDict)
		}, function(errorStr) {
		 	
		});
	}
	
	function updateUI(dataDict){
		for (var i = 0; i < domArr.length; i++) {
			var oneDom = domArr[i]
			var dom = $('#'+oneDom['domId'])[0]
			dom.innerText = dataDict[oneDom['key']]
			if (oneDom['type'] == 'input') {
				dom.value = dataDict[oneDom['key']]
			}else if (oneDom['type'] == 'list') {
				dom.setAttribute('data-id',dataDict[oneDom['key']])
				dom.innerText = dataDict[oneDom['key']+'Desc']
			}
		}
	}
	
	function getDeviceDateStr(){
		var currentDate = new Date();
		var cyear = currentDate.getFullYear();
		var cmonth = currentDate.getMonth() + 1;
		var cday = currentDate.getDate();
		var thisDay = cyear + "-" 
		if (cmonth < 10) {
			thisDay +='0'
		}
		thisDay+= cmonth + "-" 
		if (cday < 10) {
			thisDay +='0'
		}
		thisDay += cday;
		return thisDay;
	}

	function baseSetup(){
		$('.mui-scroll-wrapper').scroll({
			bounce: true,
			indicators: false, //是否显示滚动条
		});
		var self = plus.webview.currentWebview()
		sourceData = self.data
		pageType = self.pageType
		if (sourceData) { //修改
			getTransDetail()
		}
		perInfo = self.perInfo
		perid = perInfo['loginPerID']
		$('#CreatorName')[0].innerText = perInfo['loginName']
		$('#applyLoc')[0].innerText = perInfo['loginWardDesc']
		//关闭按钮
		mui('body').on('tap','#closeBtn',function(){
			blurAllInput()
			mui.back()
		})
		//保存提交按钮
		mui('body').on('tap','.submitBtn',submitNewData)
		// 日期
		mui('#UL').on('tap','.dateType',selectDateNew);
		//层级
		mui('#UL').on('tap','.listType',downListElementTapped);
		window.addEventListener('resize',windowResize)
	}
	
	function selectDateNew(){
		blurAllInput()
		var _self = this
		if(_self.picker) {
			_self.picker.show(function(rs) {
				_self.innerText = rs.text
				_self.picker.dispose();
				_self.picker = null;
			});
		} else {
			var options = {type:'date',endDate:new Date()};
			_self.picker = new mui.DtPicker(options);
			_self.picker.show(function(rs) {
				_self.innerText = rs.text
				_self.picker.dispose();
				_self.picker = null;
			});
		}
	}
	
})(mui)

